<?php 
## include required files
/*******************************/
require_once '../../includefiles.php';
include_once("../../model/users.php");
include_once("../../model/trade.php");
include_once("../../model/budget.php");
require_once "../../includes/classes/paging_htacess.php";
require_once '../../redirect.php';

checkUserLogin();

if($_SESSION['user_type'] == '3')
{
	@header("location:".SITE_URL."/");
	exit;
}

$userObj = new Model_Users();
$tradeObj = new Model_TRADE();
$budgetObj = new Model_Budget();


$userId = $_SESSION['getbids_id'];

$userDetArray = $userObj->getUserDetailsByUserId($userId);
$smarty->assign('userDetArray',$userDetArray);

if($userDetArray['tradeid']!='')
{
	$explodestr= @explode(",",$userDetArray['tradeid']);
	for($i=0;$i<count($explodestr);$i++)
	{
		$newstrarray[$i]="'".$explodestr[$i]."'";
	} 
	$implodestr = @implode(",",$newstrarray);
	
	if($implodestr){
	$jobtypeArray = $tradeObj->new_getAllJobtypeByTradeId($implodestr);
	$smarty->assign('jobtypeArray',$jobtypeArray);
	}
}
if($_POST['jobtypeid']!='')
{
	$jobtypeid = $_POST['jobtypeid'];	
}
else if($_GET['id2']!='')
{
	$jobtypeid = base64_decode($_GET['id2']);
}
else
	$jobtypeid = '';
	
$smarty->assign('jobtypeid',$jobtypeid);

$alljobsArray = $userObj->getAllJOBFormpostalcodeTradeIdJobID($jobtypeid,$userDetArray['workarea'],$userDetArray['tradeid'],$userDetArray['jobtype']);
$total_rows= count($alljobsArray);
# --------- Pagination Part1 ---------- #
$page = $_GET['id1'];
if(!isset($_GET['id1']))
$page = 1;
else
$page = $page;
$smarty->assign("page",$page);
$rowsperpage = 10; 
$offset = $rowsperpage * ($page-1);
$smarty->assign("total_rows",$total_rows);
$smarty->assign("rowsperpage",$rowsperpage);
if($total_rows > 0) 
{
	$alljobsArray = $userObj->getAllJOBFormpostalcodeTradeIdJobID($jobtypeid,$userDetArray['workarea'],$userDetArray['tradeid'],$userDetArray['jobtype'],$rowsperpage, $offset);
	$total_pages = ceil($total_rows / $rowsperpage);
	
	for($i=0;$i<count($alljobsArray);$i++)
	{
		if($alljobsArray[$i]['trade_id']!='')
		{
			$gettradedetail = $tradeObj->getTradeCategoryDetailsById($alljobsArray[$i]['trade_id']);
			$alljobsArray[$i]['tradename'] = $gettradedetail['trade_category'];
		}
		
		if($alljobsArray[$i]['jobtype_id']!='')
		{
			$getjobtypedetail = $tradeObj->getTradeCategoryDetailsById($alljobsArray[$i]['jobtype_id']);
			$alljobsArray[$i]['jobtypename'] = $getjobtypedetail['trade_category'];
		}
		
		if($alljobsArray[$i]['approx_budget']!='')
		{
			$getbudgetdetail = $budgetObj->getBudgetDetailsById($alljobsArray[$i]['approx_budget']);
			$alljobsArray[$i]['budgetname'] = $getbudgetdetail['budget_name'];
		}
		
		if($alljobsArray[$i]['postjob_id']!='')
		{
			$getuserjobviewArr = $userObj->getUserViewjobDetailsByUserIdJobId($userId,$alljobsArray[$i]['postjob_id']);
			if($getuserjobviewArr['id'] == '')
				$alljobsArray[$i]['jobdetail'] = "View Detail";
			else
				$alljobsArray[$i]['jobdetail'] = "Interested";	
		}
	}
//echo"<pre>";print_R($alljobsArray);die();
	$smarty->assign('alljobsArray',$alljobsArray);		
	$showing   = !isset($_GET["id1"]) ? 1 : $page;
	if($jobtypeid!='')
		$firstlink = base64_encode($jobtypeid)."/leads";
	else
		$firstlink = "leads";
	$baselink  = $firstlink;
	$pagenation = pagination($total_pages, $show, $showing, $firstlink, $baselink,"", "leads");
	
	$smarty->assign("pagenation",$pagenation);
	$smarty->assign("page",$page);
}



if($_SESSION['msg'] != ''){
	$smarty->assign("msg", $_SESSION['msg']);	
	unset($_SESSION['msg']);
}
if($_SESSION['sucmsg'] != ''){
	$smarty->assign("sucmsg", $_SESSION['sucmsg']);	
	unset($_SESSION['sucmsg']);
}
if($_SESSION['error'] != ''){
	$smarty->assign("errorMsg", $_SESSION['error']);	
	unset($_SESSION['error']);
}
$active ="myaccount";
$smarty->assign('active',$active);
$subactive ="leads";
$smarty->assign('subactive',$subactive);
$smarty->assign('mainmenu',"8");



$smarty->display(TEMPLATEDIR.'/modules/leads/leads1.tpl');
unset($smarty);
?>
